package com.dongdongshop.data;

import com.dongdongshop.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor //无参构造器
@AllArgsConstructor //全参构造器
@Accessors(chain = true) //链式编程
public class Result<T> {
    private Integer code;  //返回状态码
    private String message;   //返回提示信息
    private T data;   //返回数据

    public static Result reponse(ResultEnum resultEnum){
        Result result = new Result(resultEnum.getCode(),resultEnum.getMessage());
        return result;
    }

    public static Result FAIL(ResultEnum resultEnum){
        Result result = new Result(resultEnum.ERROR.getCode(),resultEnum.ERROR.getMessage());
        return result;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }

    public static Result OK(){
        Result result = new Result(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMessage());
        return result;
    }

    public Result(Integer code,String message){
        this.code = code;
        this.message = message;
    }

}